<template>
	<view>
		<van-dialog
		  use-slot
		  async-close
		  :show="dialogShow"
		  show-cancel-button
		  @close="onClose"
		>
		<view class="dialog">
			<view class="dialog-title van-hairline--bottom">
				{{dialogType}}
			</view>
		</view>
		<van-field
		  :value="password"
		  type="password"
		  label="交易密码"
		  :border="false"
		  @change="onPssword"
		  placeholder="请输入交易密码"
		/>
		</van-dialog>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	props: {
		dialogType: {
			type: String
		},
		dialogShow: {
			type: Boolean
		}
	},
	data() {
		return {
			sum: '',
			password: ''
		};
	},
	onReady() {
	},
	onLoad() {},
	computed: {
		...mapGetters({
			userInfo: 'getUserInfo'
		})
	},
	methods: {
		onClose(event) {
			if (event.detail === 'confirm') {
			  // 异步关闭弹窗
			  this.$http.buyLABpwd({
				 uid: this.userInfo.id,
				 jypwd: this.password,
			  }).then(e => {
				  if (e.data.msg.toLowerCase() === 'ok') {
					this.dialogShow = false
				  	this.$emit('emitClose', 'confirm')
				  	return
				  }
				  uni.showToast({
				  	title: e.data.msg, 
				  	icon: 'none'
				  });
				  this.dialogShow = false
				  this.$emit('emitClose', 'off')
			  }).catch(err => {
				  this.$emit('emitClose', 'off')
			  })
			} else {
			  this.dialogShow = false
			  this.$emit('emitClose', 'off')
			}
			this.password = ''
		 },
		 onPssword (e) {
			 this.password = e.detail
		 },
		 blur () {
			 uni.hideKeyboard()
		 }
	}
};
</script>


<style scoped lang="scss">
	.dialog {
		&-title {
			padding: 20upx 0;
			font-size: 28upx;
			font-weight: 500;
			text-align: center;
		}
		&-sum {
			padding: 30upx;
			.sum {
				font-size: 28upx;
				color: #f4544d;
			}
		}
	}
</style>
